<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>成库品类</title>
	<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	<script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	<script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
	<div class="easyui-panel" style="border: none;">
		<div class="nav" id="nav"></div>
		<div class="easyui-panel" style="border:none;">
			<form id="ff" method="post">
                <div style="margin-bottom:20px;">
                    <label class="item-label">年份：</label>
                    <input type="text" class="easyui-combobox" id="year" name="year" style="width:128px;" data-options="panelHeight:'auto'" required="required"/>
                </div>
                <div style="margin-bottom:20px;" id="monthWrap">
                    <label class="item-label">月份：</label>
                    <input type="text"  class="easyui-combobox" id="month" name="month" style="width:128px;" data-options="panelHeight:'auto'"/>
                </div>
                <div style="margin-bottom:20px;" id="weekWrap">
                    <label class="item-label">周：</label>
                    <input type="text"  class="easyui-combobox" id="week" name="week" style="width:128px;" data-options="panelHeight:'auto'"/>
                </div>
                <div style="margin-bottom:20px">
                    <label class="item-label">品类：</label>
                    <select class="easyui-combobox" id="categorySelect" name="categoryCode" style="width:50%;"data-options="required:false,multiple:true">
                    </select>
                </div>s
				<div style="margin-bottom:20px">
					<label class="item-label" >描述：</label>
					<input class="text" name="description" style="width:50%;min-height:90px;">
				</div>

			</form>
			<div style="margin-left: 100px;margin-bottom: 20px;">
				<a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="submitForm()" style="width:80px">保存</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancelForm()" style="width:80px">取消</a>
			</div>
		</div>

	</div>
</div>
</body>
<script type="text/javascript">
    var id = getQueryParameter("id");
    var year = getQueryParameter("year");
    var month = getQueryParameter("month");
    var week = getQueryParameter("week");
    // categoryCode=getQueryParameter("categoryCode");
    $(function(){
        setNav();
        $.when(initMonthWeek("monthWrap","weekWrap"),initCategorySelect("categorySelect")).done(function(){
            initFormData();
        });
    });
    function initFormData(){

        var reportType=window.parent.workMode.toUpperCase();
        if("WEEK"==reportType ||"ONLINE"==reportType){
            month=0;
        }else{
            week=0;
        }
        if(year){
            $.ajax({
                url:config.url +"/statisticsPc/",
                type:'get',
                data:{year:year,month:month,week:week,reportType:reportType},
                xhrFields:{withCredentials:true},
                success:function(data){
                    //填充表单
                    if(data){
                        var item = changeProperty2String(data);
                        if(!item.values){
                            item.values = [];
                        }
                        $("#ff").form("load",item);
                    }
                },
                error:function(){
                }
            });
        }
        // $("#categorySelect").combobox("select",categoryCode);
        // $("#categorySelect").combobox('readonly', true);
    }

    function submitForm(){
        $("#ff").form("submit",{
            onSubmit:function(){
                var valid = $(this).form('enableValidation').form('validate');
                if(valid){
                    var formData = getFormData(document.getElementById("ff"));
                    var method = "POST";
                    // if(id){
                    //     method = "PATCH";
                    //     formData.id = id;
                    // }
                    var categoryCode = $("#categorySelect").combobox('getValues');
                    formData.categoryCode=categoryCode;
                    formData.reportType=window.parent.workMode.toUpperCase();
                    $.ajax({
                        url:config.url+"/statisticsPc",
                        type:method,
                        data:JSON.stringify(formData),
                        dataType:"json",
                        contentType:"application/json;charset=UTF-8",
                        xhrFields:{withCredentials:true},
                        beforeSend:function(){
                            $.messager.progress({
                                title:"请稍等",
                                interval:50,
                                text:"操作进行中..."
                            });
                        },
                        complete:function(){
                            $.messager.progress("close");
                        },
                        success:function(data){
                            if(data){
                                $.messager.alert("提示","操作成功","info",function () {
                                    window.parent.closeCurrentTab(true);
                                });
                            }
                        },
                        error:function(data){
                            if(data){
                                $.messager.alert("提示",data.responseJSON.message||"操作失败","error");
                            }
                        }
                    });
                    return false;
                }
                return false;
            }
        })
    }
    function cancelForm(){
        window.parent.closeCurrentTab();
    }

</script>
</html>